<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('基础业务列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>业务编号：</p>
                                <input type="text" name="businessCode"/>
                            </li>
                            <li>
                                <p>合作公司：</p>
                                <input type="text" name="company"/>
                            </li>
                            <li>
                                <p>联系人：</p>
                                <input type="text" name="contactPerson"/>
                            </li>
                            <li>
                                <p>联系方式：</p>
                                <input type="text" name="mobile"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:base:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:base:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:base:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:base:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        let editFlag = [[${@permission.hasPermi('business:base:edit')}]];
        let removeFlag = [[${@permission.hasPermi('business:base:remove')}]];
        let openFlag = [[${@permission.hasPermi('business:base:open')}]];
        let businessTypeDatas = [[${@dict.getType('sd_business_type')}]];
        let rechargeChannelDatas = [[${@dict.getType('sd_recharge_channel')}]];
        let prefix = ctx + "business/base";

        // 充值面额
        let rechargeMoneyDatas = [[${@dict.getType('sd_recharge_money')}]];

        $(function() {
            let options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "基础业务",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id',
                    title : '主键id'
                },
                {
                    field : 'businessCode',
                    title : '业务编号'
                },
                {
                    field : 'businessType',
                    title : '业务类型',
                    formatter: function(value, row, index) {
                        if (value == 0) {
                            return $.table.selectDictLabel(businessTypeDatas, value) + '-' + $.table.selectDictLabel(rechargeChannelDatas, row.rechargeChannel);
                        } else {
                            return $.table.selectDictLabel(businessTypeDatas, value);
                        }
                    }
                },
                {
                    field : 'company',
                    title : '合作公司'
                },
                {
                    field : 'contactPerson',
                    title : '联系人'
                },
                {
                    field : 'mobile',
                    title : '联系方式'
                },
                {
                    field : 'price',
                    title : '业务价格',
                    formatter: function (value, row, index) {
                        return row.prices && row.prices.length > 0 ? showPrice(row.prices) : value;
                    }
                },
                {
                    field : 'remark',
                    title : '备注'
                },
                {
                    visible: openFlag != 'hidden',
                    field : 'status',
                    title : '状态',
                    formatter : function (value, row, index) {
                        return '<i class="fa fa-toggle-' + (value == 1 ? 'off' : 'on') + ' text-info fa-2x" onclick="changeStatus(' + row.id + ')"></i> ';
                    }
                },
                {
                    field : 'userName',
                    title : '所属用户'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function changeStatus(id) {
            $.modal.confirm("确认要修改状态吗？", function() {
                $.operate.post(prefix + "/changeStatus", {id: id});
            })
        }

        function showPrice(val) {
            let content = '<table class=\'table table-hover\'><thead><tr><th><div class=\'th-inner\'>充值面额</div></th><th><div class=\'th-inner\'>实际价格</div></th></tr></thead>';
            content += '<tbody>';
            val.forEach(function (value, idx, array) {
                content += '<tr><td>'+value.label+'</td><td>'+value.money+'</td></tr>';
            });
            content += '</tbody></table>';
            return '<a data-content="'+content+'" onclick="showDetail(this)">详情</a>';
        }

        function showDetail(proxy) {
            let content = $(proxy).data('content');
            layer.open({
                title: '业务价格',
                content: content,
                shadeClose: true
            });
        }
    </script>
</body>
</html>